package Eyjafjalla.action;

import Eyjafjalla.patch.CloudPatch;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class DrawToCloudAction extends AbstractGameAction {
    public DrawToCloudAction(boolean fromBottom,int count){
        this.actionType = ActionType.CARD_MANIPULATION;
        this.amount = count;
        this.fromBottom = fromBottom;
        this.duration = Settings.ACTION_DUR_FAST;
        this.startDuration = this.duration;
    }

    @Override
    public void update() {

        if(startDuration==duration){
            CardGroup draw = AbstractDungeon.player.drawPile;
            for(int i =0;i<this.amount;i++){
                if(draw.size()>0) {
                    if (CloudPatch.cloudGroup.size() < 5) {
                        AbstractCard c;
                        if (fromBottom)
                            c = draw.getBottomCard();
                        else
                            c = draw.getTopCard();
                        if (c != null) {
                            CloudPatch.moveToCloud(draw, c);
                            c.triggerWhenDrawn();
                        }
                    } else {
                        CloudPatch.createCloudFullDialog();
                        break;
                    }
                }
            }
        }

        tickDuration();
    }

    boolean fromBottom;
}
